package org.devf.fork.imsimulator.http.listener;

import cn.hutool.json.JSONUtil;
import org.devf.fork.imsimulator.help.MyLog;
import org.devf.fork.imsimulator.http.HttpListener;

import java.util.Map;

/**
 * LogListener related
 *
 * @author wanghuafu
 * @since 1.0  2023/9/13 17:22
 */
public class LogListener implements HttpListener {

    @Override
    public void processBefore(String url, Object params, Map<String, String> header) {
        MyLog.info("接口请求：{}",url);
        MyLog.info("=>参数：{}", JSONUtil.toJsonStr(params));
        MyLog.info("=>header：{}", JSONUtil.toJsonStr(header));
    }

    @Override
    public void processAfter(String url, Object params, Map<String, String> header, Object response) {
        System.out.println("接口请求完成：" + url);
        System.out.println("=>响应信息：" + JSONUtil.toJsonStr(response));
    }

    @Override
    public void processError(String url, Object params, Map<String, String> header, String message, int httpCode) {
        System.out.println("接口请求完成：");
        System.out.println("=>响应异常：" + message + ",httpCode = " + httpCode);
    }
}
